package a2022.a20220714;

/**
 * @author lenovo
 * @date 2022/7/14
 */
public class WordFilter {
    private String[] SS;

    public WordFilter(String[] words) {
        this.SS = words;
    }

    public int f(String pref, String suff) {
        int num = -1, x = 0, y = SS.length - 1;
        while (y >= x) {

            if (SS[x].startsWith(pref) && SS[x].endsWith(suff)) num = x;
            if (SS[y].startsWith(pref) && SS[y].endsWith(suff)) return y;
            x++;
            y--;
        }


        return num;
    }

}
